<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>企业活跃排行</title>
  <link rel="stylesheet" href="../../mobile_static/css/element.css">
  <link rel="stylesheet" href="../../mobile_static/css/base.css">
  <link rel="stylesheet" href="../../mobile_static/css/trafficMetrics-headquarters/enterpriseActiveRanking.css">
  <script src="../../mobile_static/js/vue.js"></script>
  <script src="../../mobile_static/js/axios.js"></script>

</head>

<body>
  <div id="app">
    <div class="app-content">
      <!-- 导航栏 -->
      <div class="top-bar">
        <div>
          <el-button @click="backHome" type="primary" plain>返回</el-button>
        </div>
      </div>
      <!-- 表格 -->
      <div class="table-box">
        <!-- 表格标题 -->
        <div class="table-title flex middle between">
          <h2>企业活跃排行</h2>
          <div class="search-box">
            <el-input prefix-icon="el-icon-search" style="width: 200px;" v-model="searchValue" placeholder="按企业名称搜索" @change="search"></el-input>
            <el-button type="primary" @click="download">下载</el-button>
          </div>
        </div>
        <!-- 表格主体 -->
        <div class="table-main">
          <el-table :data="tableData.length&&tableData" stripe style="width: 100%" v-loading="loading" border :header-cell-style="{background: 'linear-gradient(180deg, #FAFAFA 0%, #F1F1F1 100%)',fontSize:'16px',fontWeight:'bold',color:'#000000'}">
            <el-table-column prop="g0enterprise_active_rank" label="排名" min-width="80">
            </el-table-column>
            <el-table-column prop="g0enterprise_name" min-label="企业名称" min-width="260">
            </el-table-column>
            <el-table-column prop="k0active_user_cnt" label="访问人次" min-width="120">
            </el-table-column>
            <el-table-column label="操作" prop="operation" min-width="120">
            </el-table-column>
          </el-table>
        </div>
        <!-- 分页 -->
        <div class="paging-box">
          <div class="block">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
              :current-page="thisPage" :page-sizes="[10, 20, 30, 40]" :page-size="size"
              layout="total, sizes, prev, pager, next, jumper" :total="length">
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

</html>
<script src="../../mobile_static/js/element.js"></script>
<script type="module">
  import { postOneId, getOneIdDownload } from '../../mobile_static/axios/axios.config.js'

  new Vue({
    el: "#app",
    data() {
      return {
        searchValue: "",
        startDate: "2021-01-01",
        endDate: "2022-03-08",
        size: 10,
        thisPage: 1,
        length: "",
        tableData: [],
        loading:false
      }
    },
    created() {
      this.startDate = sessionStorage.getItem('startAndEndDate') ? JSON.parse(sessionStorage.getItem("startAndEndDate"))[0]: ''
      this.endDate = sessionStorage.getItem('startAndEndDate') ? JSON.parse(sessionStorage.getItem("startAndEndDate"))[1] : ''
    },
    mounted() {
      this.RequestActiveRanking()
    },
    methods: {
      search() {
        this.thisPage = 1
        this.RequestActiveRanking()
      },
      backHome() {
        sessionStorage.removeItem('code')
        window.location.href = './trafficMetrics-headquarters.html';
      },
      handleSizeChange(val) {
        this.size = val
        this.RequestActiveRanking()
      },
      handleCurrentChange(val) {
        this.thisPage = val
        this.RequestActiveRanking()
      },
      //请求企业活跃排行数据
      RequestActiveRanking() {
        this.loading = true
        postOneId("qyhyph00", {
          pageSize: this.size,
          pageNum: this.thisPage,
          startDate: this.startDate,
          endDate: this.endDate,
          g0enterpriseName: this.searchValue
        }).then(res => {
          this.loading = false
          res = JSON.parse(res.data.msg);
          console.log(res, "请求企业活跃排行数据成功");
          if(res.total){
            this.tableData = res.data
          }else{
            this.tableData = []
          }
          this.length = res.total
          if (res.total) {
            for (let i = 0; i < this.tableData.length; i++) {
              this.$set(this.tableData[i], "operation", "查看详情")
            }
            if (this.tableData.length) {
              let tableBtnArr = document.getElementsByClassName("el-table_1_column_4");
              setTimeout(() => {
                for (let i = 1; i < tableBtnArr.length; i++) {
                  tableBtnArr[i].addEventListener("click", () => {
                    window.location.href = './activeUsersList.html?code=' + this.tableData[i - 1].g0enterprise_code + "&startDate=" + this.startDate + "&endDate=" + this.endDate;
                  })
                }
              })
            }
          }
        })
      },
      //下载
      download() {
        if (this.length > 50000) {
          this.$notify.error({
            title: '下载失败',
            message: "下载数据条数不能超过50000条",
          });
          return
        }
        this.loading = true
        getOneIdDownload("qyhyph00Export", {
          pageSize: this.length,
          pageNum: 1,
          startDate: this.startDate,
          endDate: this.endDate,
          g0enterpriseName: this.searchValue
        }).then(res => {
          if (!res) {
            return
          }
          this.loading = false
          let url = window.URL.createObjectURL(res.data)
          let link = document.createElement("a")
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', '企业活跃排行.xlsx')
          document.body.appendChild(link)
          link.click()
        })
      },
    }
  })
</script>